<template>
	<view>
		<uni-popup ref="popup" type="bottom">
			<view class="bg-white ">
				<uni-section title="邀约到访" type="circle">
					<template v-slot:right>
						<view @click="close">关闭</view>
					</template>
				</uni-section>
				<view class="padding-bottom-lg padding-sm" style="padding-bottom: 120rpx;">
					<uni-forms class="margin-sm" labelWidth="160rpx" ref="submitForm" :modelValue="from" :rules="rules">

						<view style="display: flex;">
							<view style="flex: 1;">
								<uni-forms-item label="学生姓名" required name="name"
									style="display: flex;align-items: center;">
									<view style="  ">{{from.name}}</view>

								</uni-forms-item>
								<uni-forms-item label="手机号" required name="phone"
									style="display: flex;align-items: center;">
									{{from.phone}}
								</uni-forms-item>
							</view>
						</view>
						<uni-forms-item label="年龄" required>
							<view style="display: flex;">
								<view style="width: 350rpx;"><uni-datetime-picker type="date"
										v-model="from.dateOfBirth" /></view>
								<view class="juzhong bg-olive radius margin-left-lg" style="flex: 1;">
									{{dateToAge(from.dateOfBirth)}}
								</view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="性别" required name="sex">
							<uni-data-checkbox style="width: 100%;" mode="button" v-model="from.sex"
								:localdata="sexList"></uni-data-checkbox>
						</uni-forms-item>

						<uni-forms-item label="邀约目的" required name="invitationPurpose">
							<uni-data-checkbox style="width: 100%;" mode="button" v-model="from.invitationPurpose"
								:localdata="dict.invitation_purpose"
								:map="{text:'dictName',value:'dictValue'}"></uni-data-checkbox>
						</uni-forms-item>


						<uni-forms-item label="测评年级" required>
							<uni-data-select :value="from.evaluationGrade" :localdata="dict.grade"></uni-data-select>
						</uni-forms-item>

						<uni-forms-item label="邀约时间" required>
							<uni-datetime-picker type="datetime" v-model="from.invitationTime" />
						</uni-forms-item>
					</uni-forms>
					<button @click="submitForm" class="login-btn cu-btn block bg-blue lg round">提交</button>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import {
		doInsert
	} from '@/api/marketing/evaluation/AxEvaluationRecordManagementApi.js'


	import {
		formatTime,
		dateToAge
	} from '@/utils/validate'
	import {
		getcommon,
		pictureProcessing,
	} from '@/utils/common'
	export default {

		data() {
			return {
				from: {
					customer: {

					},
					name: '',
					phone: '',
					sex: null,

					izUsable: '1',
					// 设置默认值
					version: 0,
					evaluationGrade: null,
					dateOfBirth: new Date(),
					invitationTime: new Date(),
					invitationPurpose: null,
				},

				dict: {},
				sexList: [{
						text: '男孩',
						value: 1
					},
					{
						text: '女孩',
						value: 0
					}
				],
				// 校验规则
				rules: {
					evaluationGrade: {
						rules: [{
							required: true,
							errorMessage: '测评年级不能为空'
						}]
					},
					invitationPurpose: {
						rules: [{
							required: true,
							errorMessage: '邀约目的不能为空'
						}]
					},
					invitationTime: {
						rules: [{
							required: true,
							errorMessage: '邀约时间不能为空'
						}]
					},
				},
			}

		},
		props: {
			customer: {}
		},
		mounted() {
			// this.sourceList = getcommon("sourceList")
			this.dict.invitation_purpose = this.$getDictList("invitation_purpose");
			this.dict.grade = this.$getDictList("grade");

			for (let s of this.dict.grade) {
				s.text = s.dictName
				s.value = s.dictValue
			}

		},
		methods: {

			dateToAge(date) {
				return dateToAge(date)
			},
			open(data) {
				Object.assign(this.from, this.$options.data().from);
				this.from.customer = data
				this.from.khid = data.id
				this.from.name = this.from.customer.student.name
				this.from.sex = parseInt(this.from.customer.student.sex)
				this.from.dateOfBirth = this.from.customer.student.dateOfBirth
				this.from.evaluationGrade = this.from.customer.student.grade
				this.from.phone = this.from.customer.parentsInfo.phone
				this.from.invitationTime = formatTime(this.from.invitationTime)
				console.log(this.from);
				this.$refs.popup.open()
			},
			async submitForm() {

				this.$refs['submitForm'].validate().then(async res => {
					let {
						success
					} = await doInsert(this.from)
					let _this = this
					if (success) {
						uni.showModal({
							title: "邀约成功",
							content: "是否前往测评中心下载材料?",
							success() {
								uni.navigateTo({
									url: "/pages/marketing/evaluation/index"
								})
							}
						})
					}
				})

			},


			close() {
				Object.assign(this.$data, this.$options.data());
				this.$refs.popup.close()
				// uni.showTabBar();
				this.$emit('refresh')
			},


		}
	}
</script>

<style>
</style>